import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;

public class ValidInputGetter {


    private PrintStream printStream;
    private BufferedReader bufferedReader;
    private GameBoard gameBoard;

    public ValidInputGetter(PrintStream printStream, BufferedReader bufferedReader, GameBoard gameBoard) {
        this.printStream = printStream;
        this.bufferedReader = bufferedReader;
        this.gameBoard = gameBoard;
    }

    public int getValidInput() throws IOException {
        printStream.println("It is Player1's Turn to Make a Move! Choose a number 1-9");

        String stringInteger = bufferedReader.readLine();
        int userInput = Integer.parseInt(stringInteger);

        while(!gameBoard.isValid(userInput)){
            printStream.println("Location already taken \n Choose a number 1-9");
            stringInteger = bufferedReader.readLine();
            userInput = Integer.parseInt(stringInteger);
        }

        return userInput;
    }
}
